package cp3120.model;

import cp3120.dao.DAOFactory;

/**
 * Ticket Class
 * User: Rowan Spence
 * Date: 20/05/2009
 * Time: 7:15:23 PM
 * Object used to hold ticket data for program use
 */
public class Ticket {
    private Flight flight;
    private String firstName;
    private String lastName;
    private static float gstPercentage = Float.parseFloat(DAOFactory.getVariableDAO().getVariable("GST"));
    private float gst;
    private float price;


    public Ticket() {}

    public Ticket(Flight flight, String firstName, String lastName) {
        setFlight(flight);
        this.firstName = firstName;
        this.lastName = lastName;
    }

    public float getPrice() {
        return price + gst;
    }

    // SIMPLE GETTERS
    public Flight getFlight() {
        return flight;
    }

    public String getFirstName() {
        return firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public float getGST() {
        return gst;
    }

    // SIMPLE SETTERS
    public void setFlight(Flight flight) {
        this.flight = flight;
        resetPrice();
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public String toString() {
        return Float.toString(getPrice());
    }

    public void setPrice(float price) {
        this.price = price;
        gst = price * gstPercentage;
    }

    void resetPrice() {
        price = flight.getPrice();
        gst = flight.getPrice() * gstPercentage;
    }
}